/*LICENSE_BEGIN
 * ******************************************************************
 * All original parts of SoccerScope2003 have copyright (2003) by
 * Team YowAI, represented by Mr. Shuhei Shiota
 * The Department of Creative Informatics
 * The Graduate School of Information Science and Technology
 * The University of Tokyo
 * 
 * Additional classes (except libraries in /lib) were developed by 
 * the Dainamite Robocup-Team of the DAI-Labor, TU-Berlin 
 * (www.dai-labor.de)
 * 
 * Extended/new classes/packages are:
 *   soccerscope.analyzer.LogfileAnalyzer
 *   soccerscope.daistatistic.*
 *   soccerscope.daistatistic.charts.*
 *   soccerscope.daistatistic.tools.*
 *   soccerscope.db.*
 *   soccerscope.dialog.*
 *   soccerscope.model.PlayerWorldModel
 *   soccerscope.model.SimplePlayer
 *   soccerscope.net.AgentConnector
 *   soccerscope.training.*
 *   soccerscope.training.conditions.*
 * ******************************************************************
LICENSE_END*/
package soccerscope.daistatistic;

import java.awt.Button;
import java.awt.Choice;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Event;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.GraphicsEnvironment;
import java.awt.Label;
import java.awt.Panel;
import java.awt.TextField;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.JTable;

import soccerscope.SoccerScope;
import soccerscope.SoccerScopeMenuBar;
import soccerscope.daistatistic.charts.ChartCreator;
import soccerscope.daistatistic.charts.DataHistory;
import soccerscope.daistatistic.charts.InfoFrame;
import soccerscope.daistatistic.charts.OutputFrame;
import soccerscope.daistatistic.charts.XYDataset11SeriesImpl;
import soccerscope.model.Param;

/**
 * 
 * this class represents the statistic dialog selects player and chart type and
 * shows that chart in a frame
 * 
 */
public class StatisticDialog extends Frame implements MouseListener, ActionListener,
        WindowListener {

    /*
     * init and/or alocate variables
     */
    private static final long serialVersionUID = 3904956452224120630L;

    // the dimensions of the dialog
    private static int dialogWidth = 500;

    private static int dialogHigh = 350;

    // allocate choice selectors
    private Choice selectedPlayer;

    private static Choice selectedEnemyPlayer;

    // init selections of choice selectors
    private static int playerNumber = 1;

    private static int chartType = 1;

    // allocate output frames
    private static OutputFrame chartFrame;

    private static InfoFrame infoFrame;

    // allocate the main class and the soccerscope menubar /needed to inform
    // when the statistic dialog was closed
    private static SoccerScope sooccerScope;

    private static SoccerScopeMenuBar menuBar;

    // allocate variable which holds the maximal desktop windows height
    private static int maximumWindowsHeight;

    private static Label absoluteValueLabel = new Label("Maximum absolute value");

    private static TextField abloluteValueTextField = new TextField("0");

    private static Label minMaxLabel = new Label("Min/Max Ball distance");

    private static TextField maxTextField = new TextField("105");

    private static TextField minTextField = new TextField("0");

    private static JTable chartSelectionTable;

    /**
     * 
     * the constructor for the StatisticDialog
     * 
     * @param SoccerScopeMenuBar
     * @param SoccerScope
     */
    public StatisticDialog(SoccerScopeMenuBar bar, soccerscope.SoccerScope frame) {

        // layout all items

        // main layout
        setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0));

        Panel absoluteValuePanel = new Panel();
        absoluteValuePanel.setLayout(new FlowLayout(FlowLayout.CENTER));
        abloluteValueTextField.setPreferredSize(new Dimension(40, 20));
        absoluteValuePanel.add("West", absoluteValueLabel);
        absoluteValuePanel.add("East", abloluteValueTextField);

        // create the player selector choice menu
        Panel selectPanel = new Panel();
        this.selectedPlayer = new Choice();
        this.selectedPlayer.addItemListener(new StatisticItemListener(1, 0));
        this.selectedPlayer.addItem("Player 1 (left)");
        this.selectedPlayer.addItem("Player 2 (left)");
        this.selectedPlayer.addItem("Player 3 (left)");
        this.selectedPlayer.addItem("Player 4 (left)");
        this.selectedPlayer.addItem("Player 5 (left)");
        this.selectedPlayer.addItem("Player 6 (left)");
        this.selectedPlayer.addItem("Player 7 (left)");
        this.selectedPlayer.addItem("Player 8 (left)");
        this.selectedPlayer.addItem("Player 9 (left)");
        this.selectedPlayer.addItem("Player 10 (left)");
        this.selectedPlayer.addItem("Player 11 (left)");
        this.selectedPlayer.addItem("Player 1 (right)");
        this.selectedPlayer.addItem("Player 2 (right)");
        this.selectedPlayer.addItem("Player 3 (right)");
        this.selectedPlayer.addItem("Player 4 (right)");
        this.selectedPlayer.addItem("Player 5 (right)");
        this.selectedPlayer.addItem("Player 6 (right)");
        this.selectedPlayer.addItem("Player 7 (right)");
        this.selectedPlayer.addItem("Player 8 (right)");
        this.selectedPlayer.addItem("Player 9 (right)");
        this.selectedPlayer.addItem("Player 10 (right)");
        this.selectedPlayer.addItem("Player 11 (right)");
        selectPanel.add("West", this.selectedPlayer);

        Panel minMaxPanel = new Panel();
        maxTextField.setPreferredSize(new Dimension(40, 20));
        minTextField.setPreferredSize(new Dimension(40, 20));
        minMaxPanel.add("West", minMaxLabel);
        minMaxPanel.add("Center", minTextField);
        minMaxPanel.add("East", maxTextField);

        Panel enemySelect = new Panel(new FlowLayout(FlowLayout.CENTER));
        selectedEnemyPlayer = new Choice();
        selectedEnemyPlayer.addItemListener(new StatisticItemListener(2, 0));
        selectedEnemyPlayer.addItem("Player 1");
        selectedEnemyPlayer.addItem("Player 2");
        selectedEnemyPlayer.addItem("Player 3");
        selectedEnemyPlayer.addItem("Player 4");
        selectedEnemyPlayer.addItem("Player 5");
        selectedEnemyPlayer.addItem("Player 6");
        selectedEnemyPlayer.addItem("Player 7");
        selectedEnemyPlayer.addItem("Player 8");
        selectedEnemyPlayer.addItem("Player 9");
        selectedEnemyPlayer.addItem("Player 10");
        selectedEnemyPlayer.addItem("Player 11");
        enemySelect.add(new Label("Teammate/Opponent: ", Label.RIGHT));
        enemySelect.add(selectedEnemyPlayer, Choice.LEFT_ALIGNMENT);

        chartSelectionTable = new JTable();
        chartSelectionTable.setRowSelectionAllowed(false);
        chartSelectionTable.setColumnSelectionAllowed(false);
        chartSelectionTable.addMouseListener(this);
        chartSelectionTable.setPreferredSize(new Dimension(490, 13 * chartSelectionTable
                .getRowHeight()));
        chartSelectionTable.setModel(new StatisticDialogSelectionTableModel());

        Panel refreshPanel = new Panel();
        Button go1 = new Button("Refresh");
        go1.addActionListener(this);
        go1.setActionCommand("Refresh");
        refreshPanel.add("Center", go1);

        // add all panels to main layout
        add(selectPanel);
        add(minMaxPanel);
        add(enemySelect);
        add(absoluteValuePanel);
        add(chartSelectionTable);
        add(refreshPanel);

        // setting the main window and the soccerscope menu bar
        sooccerScope = frame;
        menuBar = bar;

        // get and set the maximum desktop height
        maximumWindowsHeight = GraphicsEnvironment.getLocalGraphicsEnvironment()
                .getMaximumWindowBounds().height;

        // init the statistic dialog frame
        this.setTitle("Statistic selection Window"); // set title
        setSize(dialogWidth, dialogHigh); // set size

        int y = sooccerScope.getY() + sooccerScope.getHeight(); // show the
        // statistic
        // dialog at
        // bottom left
        // to the main
        // window
        while (y > maximumWindowsHeight - dialogHigh) {
            y--;
        }

        setLocation(sooccerScope.getX(), y); // set location
        setBackground(Color.LIGHT_GRAY); // set background color
        addWindowListener(this); // add window listener
        setVisible(true); // and show
    }

    /**
     * 
     * getter for the absolute value textfield, returns 0 if the textfield
     * contains no double number
     * 
     * @return double the number of the textfield
     */
    static double getMaxAbsoluteValue() {
        double i;
        try {
            i = Double.parseDouble(abloluteValueTextField.getText());

        } catch (Exception e) {
            i = 0;
        }
        return i;
    }

    /**
     * 
     * getter for the maximum distance textfield, returns 0 if the textfield
     * contains no double number
     * 
     * @return double the number of the textfield
     */
    public static double getMaxDistanceTextField() {
        double i;
        try {
            i = Double.parseDouble(maxTextField.getText());

        } catch (Exception e) {
            i = 0;
        }
        return i;
    }

    /**
     * 
     * getter for the minumum distance textfield, returns 0 if the textfield
     * contains no double number
     * 
     * @return double the number of the textfield
     */
    public static double getMinDistanceTextField() {
        double i;
        try {
            i = Double.parseDouble(minTextField.getText());

        } catch (Exception e) {
            i = 0;
        }
        return i;
    }

    /**
     * 
     * cleans the values from values greater/smaller than maximum absolute value
     * replaces the value with the values at i-1 if maximum absolute value = 0
     * it means that nothing is to change
     * 
     * @param double[]
     *            the values to clean
     * @return double[] the cleaned values
     */
    static double[] cleanToMaxAbsValue(double[] values) {
        double max = getMaxAbsoluteValue();
        if (max == 0)
            return values;
        for (int i = 0; i < values.length; i++) {
            if (i > 0) {

                // replace the value with the value at i-1 if needed
                // perhaps replacing with 0 ist better?
                if (values[i] > max || values[i] < -max)
                    values[i] = values[i - 1];
            } else {
                if (values[i] > max || values[i] < -max)
                    values[i] = 0;
            }
        }
        return values;
    }

    /**
     * 
     * set's the actual player. Used by itemStateChanged listener of player
     * choice selector
     * 
     * @param int
     *            the player number
     */
    public static void setPlayerOfSelector(int player) {
        playerNumber = player;
        if (Register.getPlayerBeanWithPlayerNumber(player) == null)
            Toolkit.getDefaultToolkit().beep();
    }

    /**
     * 
     * setter for the actual chart choice
     * 
     * @param int
     *            the number of the chart
     */
    public static void setChartOfSelector(int chart) {
        chartType = chart;
    }

    /**
     * 
     * if chartFrame was closed set chartFrame to null to save system resources
     * 
     */
    public static void chartFrameClosed() {
        chartFrame = null;
    }

    /**
     * 
     * if infoFrame was closed set infoFrame to null to save system resources
     * 
     */
    public static void infoFrameClosed() {
        infoFrame = null;
    }

    /**
     * 
     * perform output frame actions, depends on choice selectors and table
     * selection called by the statisticFrameListener and the
     * statisticItemListener
     */
    public static void action() {

        double[] values = new double[0]; // contains the chart values
        String msg = "Error: ";
        String msg2 = "";

        if (chartFrame == null && chartType != 35 && chartType != 50)
            chartFrame = new OutputFrame(); // if the frame does not exist
        // create output chartFrame

        if (chartType == 50) { // state statistic
            // getting the values from dataHistory

            // infoFrame.setFileName("State Statistic"); //set the file name for
            // the chart
            return;
        }

        String sideName = " (left)";
        int sidePlayerNumber = playerNumber;
        if (playerNumber > Param.MAX_PLAYER) {
            sideName = " (right)";
            sidePlayerNumber -= Param.MAX_PLAYER;
        }
        // create a jFreeChart / depending on selected chart type
        if (chartType == 1) { // create and set a stamina image to chartFrame

            // getting the values from dataHistory
            values = cleanToMaxAbsValue(DataHistory.perform(playerNumber,
                    DataHistory.Mode_StaminaOfPlayer));
            chartFrame.setFreeChart(ChartCreator.createXYFreeChart(
                    "Stamina Analyzer Player " + sidePlayerNumber + sideName, "Cycles", "Stamina",
                    "Stamnina", soccerscope.daistatistic.charts.DataHistory
                            .getCycleArray(), values), values.length);
            chartFrame.setFileName("Stamina Player " + playerNumber); // set
            // the
            // file
            // name
            // for
            // the
            // chart

        }
        if (chartType == 2) { // create and set a view angle image to
            // chartFrame

            // //getting the values from dataHistory
            values = cleanToMaxAbsValue(DataHistory.perform(playerNumber,
                    DataHistory.Mode_ViewAngleOfPlayer));
            chartFrame.setFreeChart(ChartCreator.createXYFreeChart(
                    "View Angle Analyzer Player " + sidePlayerNumber + sideName, "Cycles", "Angle",
                    "View Angle", soccerscope.daistatistic.charts.DataHistory
                            .getCycleArray(), values), values.length);
            chartFrame.setFileName("View Angle Player " + playerNumber); // set
            // the
            // file
            // name
            // for
            // the
            // chart

            double degree45 = 0;
            double degree90 = 0;
            double other = 0;
            for (int i = 0; i < values.length; i++) {
                if (values[i] == 45)
                    degree45++;
                else if (values[i] == 90)
                    degree90++;
                else
                    other++;
            }
            degree45 = (100 * degree45) / values.length;
            degree90 = (100 * degree90) / values.length;
            other = (100 * other) / values.length;
            msg = "45 degree: " + degree45 + "%" + " 90 degree: " + degree90 + "%"
                    + " other: " + other + "%";
        }
        if (chartType == 3) {
            // getting the values from dataHistory
            values = cleanToMaxAbsValue(DataHistory.perform(playerNumber,
                    DataHistory.Mode_BodyAngleOfPlayer));
            chartFrame.setFreeChart( // create and set a body angle image to
                    // chartFrame
                    ChartCreator.createXYFreeChart("Body Angle Player " + sidePlayerNumber + sideName,
                            "Cycles", "Angle", "Body Angle",
                            soccerscope.daistatistic.charts.DataHistory.getCycleArray(),
                            values), values.length);
            chartFrame.setFileName("Body Angle Player " + playerNumber); // set
            // the
            // file
            // name
            // for
            // the
            // chart
        }
        if (chartType == 4) {
            // getting the values from dataHistory
            values = cleanToMaxAbsValue(DataHistory.perform(playerNumber,
                    DataHistory.Mode_NeckAngleOfPlayer));
            chartFrame.setFreeChart( // create and set a neck angle image to
                    // chartFrame
                    ChartCreator.createXYFreeChart("Neck Angle Analyzer Player "
                            + sidePlayerNumber + sideName, "Cycles", "Angle", "Neck Angle",
                            soccerscope.daistatistic.charts.DataHistory.getCycleArray(),
                            values), values.length);
            chartFrame.setFileName("Neck Angle Player " + playerNumber); // set
            // the
            // file
            // name
            // for
            // the
            // chart
        }
        if (chartType == 5) {
            // getting the values from dataHistory
            values = cleanToMaxAbsValue(DataHistory.perform(playerNumber,
                    DataHistory.Mode_ViewQualityOfPlayer));
            chartFrame.setFreeChart( // create and set a view quality image
                    // to chartFrame
                    ChartCreator.createXYFreeChart("View Quality Analyzer Player "
                            + sidePlayerNumber + sideName, "Cycles", "Quality", "View Quality",
                            soccerscope.daistatistic.charts.DataHistory.getCycleArray(),
                            values), values.length);
            chartFrame.setFileName("View Quality Player " + playerNumber); // set
            // the
            // file
            // name
            // for
            // the
            // chart
        }
        if (chartType == 6) {
            // getting the values from dataHistory
            values = cleanToMaxAbsValue(DataHistory.perform(playerNumber,
                    DataHistory.Mode_AbsPostitionDifferenceOfPlayer));
            chartFrame.setFreeChart(ChartCreator.createXYFreeChart(
                    "Abs Position Difference Player " + sidePlayerNumber + sideName, "Cycles",
                    "Difference", "difference in meter",
                    soccerscope.daistatistic.charts.DataHistory.getCycleArray(), values),
                    values.length);
            chartFrame.setFileName("Abs Position Difference Player " + playerNumber); // set
                                                                                        // the
                                                                                        // file
                                                                                        // name
                                                                                        // for
                                                                                        // the
                                                                                        // chart
        }
        if (chartType == 7) {
            // getting the values from dataHistory
            values = cleanToMaxAbsValue(DataHistory.perform(playerNumber,
                    DataHistory.Mode_XPostitionDifferenceOfPlayer));
            chartFrame.setFreeChart(ChartCreator.createXYFreeChart(
                    "X Position Difference Player " + sidePlayerNumber + sideName, "Cycles",
                    "Difference", "difference in meter",
                    soccerscope.daistatistic.charts.DataHistory.getCycleArray(), values),
                    values.length);
            chartFrame.setFileName("X Position Difference Player " + playerNumber); // set
                                                                                    // the
                                                                                    // file
                                                                                    // name
                                                                                    // for
                                                                                    // the
                                                                                    // chart
        }
        if (chartType == 8) {
            // getting the values from dataHistory
            values = cleanToMaxAbsValue(DataHistory.perform(playerNumber,
                    DataHistory.Mode_YPostitionDifferenceOfPlayer));
            chartFrame.setFreeChart(ChartCreator.createXYFreeChart(
                    "Y Position Difference Player " + sidePlayerNumber + sideName, "Cycles",
                    "Difference", "difference in meter",
                    soccerscope.daistatistic.charts.DataHistory.getCycleArray(), values),
                    values.length);
            chartFrame.setFileName("Y Position Difference Player " + playerNumber); // set
                                                                                    // the
                                                                                    // file
                                                                                    // name
                                                                                    // for
                                                                                    // the
                                                                                    // chart
        }

        if (chartType == 9) {
            // getting the values from dataHistory
            values = cleanToMaxAbsValue(DataHistory.perform(playerNumber,
                    DataHistory.Mode_SpeedDifference));
            chartFrame.setFreeChart(ChartCreator.createXYFreeChart(
                    "Speed difference Player " + sidePlayerNumber + sideName, "Cycles", "Difference",
                    "difference in meter", soccerscope.daistatistic.charts.DataHistory
                            .getCycleArray(), values), values.length);
            chartFrame.setFileName("Speed difference Player " + playerNumber); // set
            // the
            // file
            // name
            // for
            // the
            // chart
        }
        if (chartType == 10) {
            // getting the values from dataHistory
            values = cleanToMaxAbsValue(DataHistory.perform(playerNumber,
                    DataHistory.Mode_SpeedXDiff));
            chartFrame.setFreeChart(ChartCreator.createXYFreeChart(
                    "Speed X difference Player " + sidePlayerNumber + sideName, "Cycles", "Difference",
                    "difference in meter", soccerscope.daistatistic.charts.DataHistory
                            .getCycleArray(), values), values.length);
            chartFrame.setFileName("Speed X diff. Player " + playerNumber); // set
            // the
            // file
            // name
            // for
            // the
            // chart
        }
        if (chartType == 11) {
            // getting the values from dataHistory
            values = cleanToMaxAbsValue(DataHistory.perform(playerNumber,
                    DataHistory.Mode_SpeedYDiff));
            chartFrame.setFreeChart(ChartCreator.createXYFreeChart(
                    "Speed Y difference Player" + sidePlayerNumber + sideName, "Cycles", "Difference",
                    "difference in meter", soccerscope.daistatistic.charts.DataHistory
                            .getCycleArray(), values), values.length);
            chartFrame.setFileName("Speed Y diff. Player " + playerNumber); // set
            // the
            // file
            // name
            // for
            // the
            // chart
        }
        if (chartType == 12) {
            // getting the values from dataHistory
            values = cleanToMaxAbsValue(DataHistory.perform(playerNumber,
                    DataHistory.Mode_NeckAngleDifference));
            chartFrame.setFreeChart(ChartCreator.createXYFreeChart(
                    "Neck angle difference Player " + sidePlayerNumber + sideName, "Cycles",
                    "Difference", "difference in meter",
                    soccerscope.daistatistic.charts.DataHistory.getCycleArray(), values),
                    values.length);
            chartFrame.setFileName("Neck angle difference Player " + playerNumber); // set
                                                                                    // the
                                                                                    // file
                                                                                    // name
                                                                                    // for
                                                                                    // the
                                                                                    // chart
        }

        if (chartType == 13) {
            // getting the values from dataHistory
            values = cleanToMaxAbsValue(DataHistory.perform(playerNumber,
                    DataHistory.Mode_BodyAngleDifference));
            chartFrame.setFreeChart(ChartCreator.createXYFreeChart(
                    "Body angle difference Player " + sidePlayerNumber + sideName, "Cycles",
                    "Difference", "difference in meter",
                    soccerscope.daistatistic.charts.DataHistory.getCycleArray(), values),
                    values.length);
            chartFrame.setFileName("Body angle difference Player " + playerNumber); // set
                                                                                    // the
                                                                                    // file
                                                                                    // name
                                                                                    // for
                                                                                    // the
                                                                                    // chart
        }
        if (chartType == 14) {
            // getting the values from dataHistory
            values = cleanToMaxAbsValue(DataHistory.perform(playerNumber,
                    DataHistory.Mode_BallPositionDiff));
            chartFrame.setFreeChart(ChartCreator.createXYFreeChart(
                    "Ball Position difference Player " + sidePlayerNumber + sideName, "Cycles",
                    "Difference", "difference in meter",
                    soccerscope.daistatistic.charts.DataHistory.getCycleArray(), values),
                    values.length);
            chartFrame.setFileName("Ball Position diff. Player " + playerNumber); // set
            // the
            // file
            // name
            // for
            // the
            // chart
        }
        if (chartType == 15) {
            // getting the values from dataHistory
            values = cleanToMaxAbsValue(DataHistory.perform(playerNumber,
                    DataHistory.Mode_BallXPosDiff));
            chartFrame.setFreeChart(ChartCreator.createXYFreeChart(
                    "Ball X Pos. difference Player " + sidePlayerNumber + sideName, "Cycles",
                    "Difference", "difference in meter",
                    soccerscope.daistatistic.charts.DataHistory.getCycleArray(), values),
                    values.length);
            chartFrame.setFileName("Ball X Pos. diff. Player " + playerNumber); // set
            // the
            // file
            // name
            // for
            // the
            // chart
        }
        if (chartType == 16) {
            // getting the values from dataHistory
            values = cleanToMaxAbsValue(DataHistory.perform(playerNumber,
                    DataHistory.Mode_BallYPosDiff));
            chartFrame.setFreeChart(ChartCreator.createXYFreeChart(
                    "Ball Y Pos. diff. Player " + sidePlayerNumber + sideName, "Cycles", "Difference",
                    "difference in meter", soccerscope.daistatistic.charts.DataHistory
                            .getCycleArray(), values), values.length);
            chartFrame.setFileName("Ball Y Pos. diff. Player " + playerNumber); // set
            // the
            // file
            // name
            // for
            // the
            // chart
        }

        if (chartType == 17) {
            // getting the values from dataHistory
            values = cleanToMaxAbsValue(DataHistory.perform(playerNumber,
                    DataHistory.Mode_BallSpeedDifference));
            chartFrame.setFreeChart(ChartCreator.createXYFreeChart(
                    "Ball Speed difference Player " + sidePlayerNumber + sideName, "Cycles",
                    "Difference", "difference in meter",
                    soccerscope.daistatistic.charts.DataHistory.getCycleArray(), values),
                    values.length);
            chartFrame.setFileName("Ball Speed difference Player " + playerNumber); // set
                                                                                    // the
                                                                                    // file
                                                                                    // name
                                                                                    // for
                                                                                    // the
                                                                                    // chart
        }
        if (chartType == 18) {
            // getting the values from dataHistory
            values = cleanToMaxAbsValue(DataHistory.perform(playerNumber,
                    DataHistory.Mode_BallSpeedXDiff));
            chartFrame.setFreeChart(ChartCreator.createXYFreeChart(
                    "Ball Speed X diff. Player " + sidePlayerNumber + sideName, "Cycles", "Difference",
                    "difference in meter", soccerscope.daistatistic.charts.DataHistory
                            .getCycleArray(), values), values.length);
            chartFrame.setFileName("Ball Speed X diff. Player " + playerNumber); // set
            // the
            // file
            // name
            // for
            // the
            // chart
        }
        if (chartType == 19) {
            // getting the values from dataHistory
            values = cleanToMaxAbsValue(DataHistory.perform(playerNumber,
                    DataHistory.Mode_BallSpeedYDiff));
            chartFrame.setFreeChart(ChartCreator.createXYFreeChart(
                    "Ball Speed Y diff. Player " + sidePlayerNumber + sideName, "Cycles", "Difference",
                    "difference in meter", soccerscope.daistatistic.charts.DataHistory
                            .getCycleArray(), values), values.length);
            chartFrame.setFileName("Ball Speed Y diff. Player " + playerNumber); // set
            // the
            // file
            // name
            // for
            // the
            // chart
        }
        if (chartType == 20) {
            // getting the values from dataHistory
            values = cleanToMaxAbsValue(DataHistory.perform(playerNumber,
                    DataHistory.Mode_BallIntercept));
            chartFrame.setFreeChart(ChartCreator
                    .createXYFreeChart(
                            "Ball Interception diff. (IP(t) - IP(t-1)) of Player "
                                    + sidePlayerNumber + sideName, "Cycles", "Difference",
                            "difference in meter",
                            soccerscope.daistatistic.charts.DataHistory.getCycleArray(),
                            values), values.length);
            chartFrame.setFileName("Ball Interception diff. (IP(t) - IP(t-1)) of Player "
                    + playerNumber); // set the file name for the
            // chart
        }
        if (chartType == 21) {
            // getting the values from dataHistory
            values = cleanToMaxAbsValue(DataHistory.perform(playerNumber,
                    DataHistory.Mode_BallInterceptX));
            chartFrame.setFreeChart(ChartCreator.createXYFreeChart(
                    "Ball Interception X diff. (IP(t) - IP(t-1)) of Player "
                            + sidePlayerNumber + sideName, "Cycles", "Difference",
                    "difference in meter", soccerscope.daistatistic.charts.DataHistory
                            .getCycleArray(), values), values.length);
            chartFrame
                    .setFileName("Ball Interception X diff. (IP(t) - IP(t-1)) of Player "
                            + playerNumber); // set the file name for the
            // chart
        }
        if (chartType == 22) {
            // getting the values from dataHistory
            values = cleanToMaxAbsValue(DataHistory.perform(playerNumber,
                    DataHistory.Mode_BallInterceptY));
            chartFrame.setFreeChart(ChartCreator.createXYFreeChart(
                    "Ball Interception Y diff. (IP(t) - IP(t-1)) of Player "
                            + sidePlayerNumber + sideName, "Cycles", "Difference",
                    "difference in meter", soccerscope.daistatistic.charts.DataHistory
                            .getCycleArray(), values), values.length);
            chartFrame
                    .setFileName("Ball Interception Y diff. (IP(t) - IP(t-1)) of Player "
                            + playerNumber); // set the file name for the
            // chart
        }

        // compex chart data sets

        if (chartType == 23 || chartType == 24) {
            // getting the values from dataHistory
            values = cleanToMaxAbsValue(DataHistory.perform(playerNumber,
                    DataHistory.Mode_BallPossession));
            String name = "Ball Possession ";

            if (chartType == 24) { // if "ball possession (lost) selected
                int nextSameTeamIndex = 0; // manipulate data of "ball
                // possession (radius)"
                double actualTeam = 0; // so that we have a chart which shows
                // ball team change

                // the algorithm to fill free fields with team fields if next
                // team is the same team

                for (int i = 0; i < values.length; i++) {

                    if (i < nextSameTeamIndex)
                        values[i] = actualTeam;
                    else {
                        if (i + 1 < values.length) {
                            if (values[i + 1] != values[i]) {
                                for (int j = i + 1; j < values.length; j++) {
                                    if (values[j] != values[i] && values[j] != 0) {
                                        i = j - 1;
                                        actualTeam = values[j];
                                        break; // i = j - 1 cause at the end of
                                        // else part i = i++ by "for i"
                                    }
                                    if (values[j] == actualTeam || values[j] == 0) {
                                        nextSameTeamIndex = j;
                                        values[j] = actualTeam;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            } else
                name = name + "(radius)";

            chartFrame.setFreeChart(ChartCreator.createXYFreeChart(name, "Cycles",
                    "Team", "Team (+1 left team, -1 right team, 0 free)",
                    soccerscope.daistatistic.charts.DataHistory.getCycleArray(), values),
                    values.length);
            chartFrame.setFileName(name); // set the file name for the chart

            double dai = 0;
            double enemy = 0;
            double free = 0;
            int length = values.length;
            for (int i = 1; i < length; i++) {
                if (values[i] == 1)
                    dai++;
                if (values[i] == -1)
                    enemy++;
                if (values[i] == 0)
                    free++;
            }
            length--;
            msg = "Ball Possession: Dai: " + Double.toString(((100 * dai) / length))
                    + " Enemy: " + Double.toString(((100 * enemy) / length)) + " Free: "
                    + Double.toString(((100 * free) / length));
        }

        if (chartType == 25) {
            // getting the values from dataHistory
            values = cleanToMaxAbsValue(DataHistory.perform(playerNumber,
                    DataHistory.Mode_Pass));
            chartFrame.setFreeChart(ChartCreator.createXYFreeChart("Pass of Player "
                    + sidePlayerNumber + sideName, "Cycles", "Player number", "player",
                    soccerscope.daistatistic.charts.DataHistory.getCycleArray(), values),
                    values.length);
            chartFrame.setFileName("Pass of Player " + playerNumber); // set
            // the
            // file
            // name
            // for
            // the
            // chart

            int numberOfPasses = 0;
            int success = 0;
            int fail = 0;

            double passToPlayer = 0;

            for (int i = 0; i < values.length; i++) {
                if (values[i] != 0 && passToPlayer == 0) {
                    passToPlayer = values[i];
                    numberOfPasses++;
                }
                if (passToPlayer != 0 && values[i] != passToPlayer) {
                    if (values[i] == 0) {
                        success++;
                    } else {
                        fail++;
                    }
                    passToPlayer = 0;
                }
            }
            msg = "Pass quota: count " + numberOfPasses + " successful: " + success;
            if (numberOfPasses != 0)
                msg = msg + " (" + ((100 * success) / numberOfPasses) + "%)";
            msg = msg + " failed: " + fail;

        }
        if (chartType == 26) {
            // getting the values from dataHistory
            values = cleanToMaxAbsValue(DataHistory.perform(playerNumber,
                    DataHistory.Mode_Holes));
            chartFrame.setFreeChart(ChartCreator.createXYFreeChart("Holes of Player "
                    + sidePlayerNumber + sideName, "Cycles", "Holes", "number of Holes",
                    soccerscope.daistatistic.charts.DataHistory.getCycleArray(), values),
                    values.length);
            chartFrame.setFileName("Holes of Player " + playerNumber); // set
            // the
            // file
            // name
            // for
            // the
            // chart
            double counter = 0;
            for (int i = 0; i < values.length; i++) {
                counter = counter + values[i];
            }
            msg = "Number of holes: " + counter + " within " + values.length + " cycles.";
        }
        if (chartType == 27) {
            // getting the values from dataHistory
            values = cleanToMaxAbsValue(DataHistory.perform(playerNumber,
                    DataHistory.Mode_BallSpeedTMinus1));
            chartFrame.setFreeChart(ChartCreator.createXYFreeChart(
                    "Ball Speed(t)-(t-1) of Player " + sidePlayerNumber + sideName, "Cycles",
                    "Difference", "difference in meter",
                    soccerscope.daistatistic.charts.DataHistory.getCycleArray(), values),
                    values.length);
            chartFrame.setFileName("Ball Speed(t)-(t-1) of Player " + playerNumber); // set
                                                                                        // the
                                                                                        // file
                                                                                        // name
                                                                                        // for
                                                                                        // the
                                                                                        // chart
        }
        if (chartType == 28) {
            // getting the values from dataHistory
            values = cleanToMaxAbsValue(DataHistory.perform(playerNumber,
                    DataHistory.Mode_DistanceBallToGoalWM));
            double[] values2 = cleanToMaxAbsValue(DataHistory.perform(playerNumber,
                    DataHistory.Mode_DistanceBallToGoalMonitor));
            chartFrame.setFreeChart(ChartCreator.createXYFreeChartWith2Series(
                    "Distance Ball to Goal of Player " + sidePlayerNumber + sideName, "Cycles",
                    "Distence in meter", "WM distance", "Monitor distance",
                    soccerscope.daistatistic.charts.DataHistory.getCycleArray(), values,
                    values2), values.length);
            chartFrame.setFileName("Distance Ball to Goal of Player " + playerNumber); // set
                                                                                        // the
                                                                                        // file
                                                                                        // name
                                                                                        // for
                                                                                        // the
                                                                                        // chart
        }
        if (chartType == 29) {
            // getting the values from dataHistory
            values = cleanToMaxAbsValue(DataHistory.perform(playerNumber,
                    DataHistory.Mode_DistanceToEnemyMonitor));
            double[] values2 = cleanToMaxAbsValue(DataHistory.perform(playerNumber,
                    DataHistory.Mode_DistanceToTeamMonitor));
            chartFrame.setFreeChart(ChartCreator.createXYFreeChartWith2Series(
                    "Distance to Enemy/Teammate of Player " + sidePlayerNumber + sideName, "Cycles",
                    "Distance in meter", "distance to enemy", "distance to teammate",
                    soccerscope.daistatistic.charts.DataHistory.getCycleArray(), values,
                    values2), values.length);
            chartFrame
                    .setFileName("Distance to Enemy/Teammate of Player " + playerNumber); // set
                                                                                            // the
                                                                                            // file
                                                                                            // name
                                                                                            // for
                                                                                            // the
                                                                                            // chart
        }
        if (chartType == 30) {
            // getting the values from dataHistory
            XYDataset11SeriesImpl set = new XYDataset11SeriesImpl();
            int help = 0;
            double totalNumberOfCycles = 0;
            double holeCount = 0;
            double inCycles = 0;
            int add = 0;
            String side = "(Team left)";
            if (playerNumber > Param.MAX_PLAYER) {
                add = Param.MAX_PLAYER;
                side = "(Team right)";
            }
            for (int i = 1 + add; i < 12 + add; i++) {

                values = cleanToMaxAbsValue(DataHistory
                        .perform(i, DataHistory.Mode_Holes));
                totalNumberOfCycles = totalNumberOfCycles + values.length;
                for (int j = 0; j < values.length; j++) {
                    holeCount = holeCount + values[j];
                    if (values[j] != 0)
                        inCycles++;
                    values[j] = values[j] + help;

                }
                set.setYValues(values, i - 1 - add);
                help = help + 2;
            }
            msg = "Total number of holes: " + holeCount + " in " + totalNumberOfCycles
                    + " cycles. Holes in " + inCycles + " cycles";
            msg2 = "Holes in " + ((inCycles / totalNumberOfCycles) * 100)
                    + "% of overall cycles.";
            set.setXValues(soccerscope.daistatistic.charts.DataHistory.getCycleArray());
            chartFrame.setFreeChart(ChartCreator.createXYFreeChartWith11Series(
                    "Holes of all Players " + side, "Cycles", "Holes",

                    set), values.length);
            chartFrame.setFileName("Holes of all Players"); // set the file name
            // for the chart
        }
        if (chartType == 31) {
            // getting the values from dataHistory
            values = cleanToMaxAbsValue(DataHistory.performWithSecondPlayer(playerNumber,
                    DataHistory.Mode_PositionOfOpponents, (selectedEnemyPlayer
                            .getSelectedIndex() + 1)));
            chartFrame.setFreeChart(ChartCreator.createXYFreeChart(
                    "Position difference of Opponent "
                            + (selectedEnemyPlayer.getSelectedIndex() + 1), "Cycles",
                    "Difference", "difference to real Position",
                    soccerscope.daistatistic.charts.DataHistory.getCycleArray(), values),
                    values.length);
            chartFrame.setFileName("Position difference of Opponent "
                    + (selectedEnemyPlayer.getSelectedIndex() + 1)); // set
            // the
            // file
            // name
            // for
            // the
            // chart
        }
        if (chartType == 32) {
            // getting the values from dataHistory
            values = cleanToMaxAbsValue(DataHistory.performWithSecondPlayer(playerNumber,
                    DataHistory.Mode_PositionOfTeammates, (selectedEnemyPlayer
                            .getSelectedIndex() + 1)));
            chartFrame.setFreeChart(ChartCreator.createXYFreeChart(
                    "Position difference of Teammate "
                            + (selectedEnemyPlayer.getSelectedIndex() + 1), "Cycles",
                    "Difference", "difference to real Position",
                    soccerscope.daistatistic.charts.DataHistory.getCycleArray(), values),
                    values.length);
            chartFrame.setFileName("Position difference of Teammate "
                    + (selectedEnemyPlayer.getSelectedIndex() + 1)); // set
            // the
            // file
            // name
            // for
            // the
            // chart
        }
        if (chartType == 33) {
            // getting the values from dataHistory
            values = cleanToMaxAbsValue(DataHistory.performWithSecondPlayer(playerNumber,
                    DataHistory.Mode_SpeedOfOpponents, (selectedEnemyPlayer
                            .getSelectedIndex() + 1)));
            chartFrame.setFreeChart(ChartCreator.createXYFreeChart(
                    "Speed difference of  Player" + sidePlayerNumber + sideName + " to Opponent "
                            + (selectedEnemyPlayer.getSelectedIndex() + 1), "Cycles",
                    "Difference", "difference to real speed",
                    soccerscope.daistatistic.charts.DataHistory.getCycleArray(), values),
                    values.length);
            chartFrame.setFileName("Speed difference of Player" + playerNumber
                    + " to Opponent " + (selectedEnemyPlayer.getSelectedIndex() + 1)); // set
            // the
            // file
            // name
            // for
            // the
            // chart
        }
        if (chartType == 34) {
            // getting the values from dataHistory
            values = cleanToMaxAbsValue(DataHistory.performWithSecondPlayer(playerNumber,
                    DataHistory.Mode_SpeedOfTeammates, (selectedEnemyPlayer
                            .getSelectedIndex() + 1)));
            chartFrame.setFreeChart(ChartCreator.createXYFreeChart(
                    "Speed difference of Player" + sidePlayerNumber + sideName + " to Teammate "
                            + (selectedEnemyPlayer.getSelectedIndex() + 1), "Cycles",
                    "Difference", "difference to real speed",
                    soccerscope.daistatistic.charts.DataHistory.getCycleArray(), values),
                    values.length);
            chartFrame.setFileName("Speed difference of Player" + playerNumber
                    + " to Teammate " + (selectedEnemyPlayer.getSelectedIndex() + 1)); // set
            // the
            // file
            // name
            // for
            // the
            // chart
        }
        if (chartType == 35) {
            // creating values
            String[] text = new String[33];
            int textLine = 0;
            text[textLine] = "Position average difference statistics of players seen by player "
                    + sidePlayerNumber + sideName;
            textLine++;
            text[textLine] = "This statistic in currently not available (soccerscope.daistatistic.StatisticDialog, Line 1047)";
            textLine++;
            /* TODO statistic getAllOpponents must be reimplementet */
            // text[textLine] = "";
            // textLine++;
            // text[textLine] = "Number getAllTeammates getAllOpponents";
            // textLine++;
            // text[textLine] = "";
            // textLine++;
            // double allAverage1 = 0;
            // double allAverage2 = 0;
            // for (int i = 0; i <
            // DaiWorldModelHistory.getGame().numberOfTeammates; i++) {
            // text[textLine] = " " + (i + 1) + " ";
            //
            // if (i < 9)
            // text[textLine] = text[textLine] + " ";
            //
            // allAverage1 = allAverage1
            // +
            // (DaiWorldModelHistory.getGame().allTeammatesAveragePositionDiffForPlayer[playerNumber
            // - 1].playerNumber[i].addedValues / DaiWorldModelHistory
            // .getGame().allTeammatesAveragePositionDiffForPlayer[playerNumber
            // - 1].playerNumber[i].entryUpdates);
            //
            // text[textLine] = text[textLine]
            // + Double
            // .toString((DaiWorldModelHistory.getGame().allTeammatesAveragePositionDiffForPlayer[playerNumber
            // - 1].playerNumber[i].addedValues / DaiWorldModelHistory
            // .getGame().allTeammatesAveragePositionDiffForPlayer[playerNumber
            // - 1].playerNumber[i].entryUpdates));
            //
            // while (text[textLine].length() < 40) {
            // text[textLine] = text[textLine] + " ";
            // }
            //
            // allAverage2 = allAverage2
            // +
            // (DaiWorldModelHistory.getGame().allOpponentsAveragePositionDiffForPlayer[playerNumber
            // - 1].playerNumber[i].addedValues / DaiWorldModelHistory
            // .getGame().allOpponentsAveragePositionDiffForPlayer[playerNumber
            // - 1].playerNumber[i].entryUpdates);
            //
            // text[textLine] = text[textLine]
            // + Double
            // .toString((DaiWorldModelHistory.getGame().allOpponentsAveragePositionDiffForPlayer[playerNumber
            // - 1].playerNumber[i].addedValues / DaiWorldModelHistory
            // .getGame().allOpponentsAveragePositionDiffForPlayer[playerNumber
            // - 1].playerNumber[i].entryUpdates));
            // textLine++;
            // }
            // text[textLine] = " ";
            // textLine++;
            // text[textLine] = "Total: " + allAverage1
            // / DaiWorldModelHistory.getGame().numberOfTeammates
            // + " " + allAverage2
            // / DaiWorldModelHistory.getGame().numberOfTeammates;
            // textLine++;
            // text[textLine] = "";
            // textLine++;
            // text[textLine] = "Number getFriendlyPlayers getEnemyPlayers";
            // textLine++;
            // text[textLine] = "";
            // textLine++;
            // allAverage1 = 0;
            // allAverage2 = 0;
            //
            // for (int i = 0; i <
            // DaiWorldModelHistory.getGame().numberOfTeammates; i++) {
            // text[textLine] = " " + (i + 1) + " ";
            //
            // if (i < 9)
            // text[textLine] = text[textLine] + " ";
            //
            // allAverage1 = allAverage1
            // +
            // (DaiWorldModelHistory.getGame().friendlyPlayersAveragePositionDiffForPlayer[playerNumber
            // - 1].playerNumber[i].addedValues / DaiWorldModelHistory
            // .getGame().friendlyPlayersAveragePositionDiffForPlayer[playerNumber
            // - 1].playerNumber[i].entryUpdates);
            //
            // text[textLine] = text[textLine]
            // + Double
            // .toString((DaiWorldModelHistory.getGame().friendlyPlayersAveragePositionDiffForPlayer[playerNumber
            // - 1].playerNumber[i].addedValues / DaiWorldModelHistory
            // .getGame().friendlyPlayersAveragePositionDiffForPlayer[playerNumber
            // - 1].playerNumber[i].entryUpdates));
            //
            // while (text[textLine].length() < 40) {
            // text[textLine] = text[textLine] + " ";
            // }
            //
            // allAverage2 = allAverage2
            // +
            // (DaiWorldModelHistory.getGame().enemyPlayersAveragePositionDiffForPlayer[playerNumber
            // - 1].playerNumber[i].addedValues / DaiWorldModelHistory
            // .getGame().enemyPlayersAveragePositionDiffForPlayer[playerNumber
            // - 1].playerNumber[i].entryUpdates);
            //
            // text[textLine] = text[textLine]
            // + Double
            // .toString((DaiWorldModelHistory.getGame().enemyPlayersAveragePositionDiffForPlayer[playerNumber
            // - 1].playerNumber[i].addedValues / DaiWorldModelHistory
            // .getGame().enemyPlayersAveragePositionDiffForPlayer[playerNumber
            // - 1].playerNumber[i].entryUpdates));
            // textLine++;
            // }
            // text[textLine] = " ";
            // textLine++;
            // text[textLine] = "Total: " + allAverage1
            // / DaiWorldModelHistory.getGame().numberOfTeammates
            // + " " + allAverage2
            // / DaiWorldModelHistory.getGame().numberOfTeammates;
            //
            if (infoFrame == null)
                infoFrame = new InfoFrame();
            infoFrame.setInfoLines(text);
            infoFrame.setFileName("Positions Statistics of Player" + playerNumber
                    + " to other " + (selectedEnemyPlayer.getSelectedIndex() + 1)); // set
            // the
            // file
            // name
            // for
            // the
            // chart
            return;
        }

        // setting average
        if (chartType != 30 && chartType != 50)
            chartFrame.setAverage(soccerscope.daistatistic.charts.DataHistory
                    .calculateAverage(values)); // calculate and set average
        else
            chartFrame.setAverage(0);

        // setting frame info text
        if (chartType != 23 && chartType != 24 && chartType != 25 && chartType != 26
                && chartType != 2 && chartType != 30 && chartType != 50) {
            chartFrame.setInfo1("Varianz: "
                    + Double.toString(soccerscope.daistatistic.charts.DataHistory
                            .calculateVarianz(values))
                    + " Standard deviation: "
                    + Double.toString(soccerscope.daistatistic.charts.DataHistory
                            .calculateStandardDeviation(values)));
            chartFrame.setInfo2("Filled Cycles "
                    + Double.toString(soccerscope.daistatistic.charts.DataHistory
                            .calculateFilledValues(values)) + "%");
        } else {
            if (chartType != 50) {
                chartFrame.setInfo1(msg);
                chartFrame.setInfo2(msg2);
            }
        }
    }

    /**
     * 
     * if an action performed search the resulting action
     * 
     * @param ActionEvent
     *            the event
     */
    public void actionPerformed(ActionEvent e) {

        String s = e.getActionCommand(); // get the ActionCommand

        // perform action with parameters for chartFrame
        if (s.equals("Refresh")) {
            action();
        }
    }

    /**
     * 
     * stop/exit the statistic dialog inform the menubar, that the dialog is
     * closing
     */
    public void stop() {
        menuBar.statisticDialogToNull(); // inform menuBar that statistic
        // dialog was closed
        dispose();
    }

    // Mouse Events
    public void mouseClicked(MouseEvent arg0) {
    }

    /**
     * select chart type - depends on selected table row and line
     * 
     * @param MouseEvent
     *            the event
     */
    public void mousePressed(MouseEvent arg0) {
        int row = chartSelectionTable.getSelectedRow();
        int col = chartSelectionTable.getSelectedColumn();

        if (row == 0) {
            if (col == 0) {
                StatisticDialog.setChartOfSelector(1);
            }// "Stamina"
            if (col == 1) {
                StatisticDialog.setChartOfSelector(5);
            }// "View Quality";
            if (col == 2) {
            }// null;
        } else if (row == 1) {
            if (col == 0) {
                StatisticDialog.setChartOfSelector(2);
            }// "View Angle";
            if (col == 1) {
                StatisticDialog.setChartOfSelector(3);
            }// "Body Angle";
            if (col == 2) {
                StatisticDialog.setChartOfSelector(4);
            }// "Neck Angle";
        } else if (row == 2) {
            if (col == 0) {
                StatisticDialog.setChartOfSelector(6);
            }// "Position absolute difference";
            if (col == 1) {
                StatisticDialog.setChartOfSelector(7);
            }// "Position X difference";
            if (col == 2) {
                StatisticDialog.setChartOfSelector(8);
            }// "Position Y difference";
        } else if (row == 3) {
            if (col == 0) {
                StatisticDialog.setChartOfSelector(9);
            }// "Speed absolute difference";
            if (col == 1) {
                StatisticDialog.setChartOfSelector(10);
            }// "Speed X difference";
            if (col == 2) {
                StatisticDialog.setChartOfSelector(11);
            }// "Speed Y difference";
        } else if (row == 4) {
            if (col == 0) {
                StatisticDialog.setChartOfSelector(12);
            }// "Neck angle difference";
            if (col == 1) {
                StatisticDialog.setChartOfSelector(13);
            }// "Body angle difference";
            if (col == 2) {
                StatisticDialog.setChartOfSelector(27);
            }// "Ball Speed(t)-(t-1)";
        } else if (row == 5) {
            if (col == 0) {
                StatisticDialog.setChartOfSelector(14);
            }// "Ball position absolute difference";
            if (col == 1) {
                StatisticDialog.setChartOfSelector(15);
            }// "Ball position X difference";
            if (col == 2) {
                StatisticDialog.setChartOfSelector(16);
            }// "Ball position Y difference";
        } else if (row == 6) {
            if (col == 0) {
                StatisticDialog.setChartOfSelector(17);
            }// "Ball speed absolute difference";
            if (col == 1) {
                StatisticDialog.setChartOfSelector(18);
            }// "Ball speed X difference";
            if (col == 2) {
                StatisticDialog.setChartOfSelector(19);
            }// "Ball speed Y difference";
        } else if (row == 7) {
            if (col == 0) {
                StatisticDialog.setChartOfSelector(20);
            }// "Ball IP absolute difference (t-1)";
            if (col == 1) {
                StatisticDialog.setChartOfSelector(21);
            }// "Ball IP X difference (t-1)";
            if (col == 2) {
                StatisticDialog.setChartOfSelector(22);
            }// "Ball IP Y difference (t-1)";
        } else if (row == 8) {
            if (col == 0) {
                StatisticDialog.setChartOfSelector(23);
            }// "Ball Possession (in radius)";
            if (col == 1) {
                StatisticDialog.setChartOfSelector(24);
            }// "Ball Possession";
            if (col == 2) {
                StatisticDialog.setChartOfSelector(25);
            }// "Player Pass";
        } else if (row == 9) {
            if (col == 0) {
                StatisticDialog.setChartOfSelector(26);
            }// "Holes";
            if (col == 1) {
                StatisticDialog.setChartOfSelector(30);
            }// "Holes (all Player)";
            if (col == 2) {
            }// null;
        } else if (row == 10) {
            if (col == 0) {
                StatisticDialog.setChartOfSelector(28);
            }// "Distance Ball to Goal";
            if (col == 1) {
                StatisticDialog.setChartOfSelector(29);
            }// "Distance to Enemy/Teammate";
            if (col == 2) {
            }// null;
        } else if (row == 11) {
            if (col == 0) {
                StatisticDialog.setChartOfSelector(31);
            }// "Position of Opponent";
            if (col == 1) {
                StatisticDialog.setChartOfSelector(32);
            }// "Position of Teammate";
            if (col == 2) {
                StatisticDialog.setChartOfSelector(35);
            }// "Position Statistics";
        } else if (row == 12) {
            if (col == 0) {
                StatisticDialog.setChartOfSelector(33);
            }// "Speed of Opponent";
            if (col == 1) {
                StatisticDialog.setChartOfSelector(34);
            }// "Speed of Teammate";
            if (col == 2) {
                StatisticDialog.setChartOfSelector(50);
            }// "State Statistic";
        }
        StatisticDialog.action();
    }

    public void mouseReleased(MouseEvent arg0) {
    }

    public void mouseEntered(MouseEvent arg0) {
    }

    public void mouseExited(MouseEvent arg0) {
    }

    // window events
    public void windowOpened(WindowEvent arg0) {
    }

    public void windowClosing(WindowEvent arg0) {
        menuBar.statisticDialogToNull();
        dispose();

    }

    public void windowClosed(WindowEvent arg0) {
    }

    public void windowIconified(WindowEvent arg0) {
    }

    public void windowDeiconified(WindowEvent arg0) {
    }

    public void windowActivated(WindowEvent arg0) {
    }

    public void windowDeactivated(WindowEvent arg0) {
    }
}

/**
 * 
 * the item listener for the pull down menus
 */
class StatisticItemListener implements ItemListener {

    int playerSelectorNumber = 0;

    int chartSelectorNumber = 0;

    /*
     * (non-Javadoc)
     * 
     * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
     */

    StatisticItemListener(int playerSelector, int chartSelector) {
        this.playerSelectorNumber = playerSelector;
        this.chartSelectorNumber = chartSelector;
    }

    public void itemStateChanged(ItemEvent arg0) {
        Choice target = (Choice) arg0.getSource();

        // if an item was selected/deselected or at the end of scrolling set
        // choice selector selections
        if (arg0.getID() == Event.LIST_SELECT || arg0.getID() == Event.LIST_DESELECT
                || arg0.getID() == Event.SCROLL_END) {

            // check and set for a player selection of player choice selector 1
            if (target.getSelectedItem().equals("Player 1 (left)")
                    && this.playerSelectorNumber == 1) {
                StatisticDialog.setPlayerOfSelector(1);
            }
            if (target.getSelectedItem().equals("Player 2 (left)")
                    && this.playerSelectorNumber == 1) {
                StatisticDialog.setPlayerOfSelector(2);
            }
            if (target.getSelectedItem().equals("Player 3 (left)")
                    && this.playerSelectorNumber == 1) {
                StatisticDialog.setPlayerOfSelector(3);
            }
            if (target.getSelectedItem().equals("Player 4 (left)")
                    && this.playerSelectorNumber == 1) {
                StatisticDialog.setPlayerOfSelector(4);
            }
            if (target.getSelectedItem().equals("Player 5 (left)")
                    && this.playerSelectorNumber == 1) {
                StatisticDialog.setPlayerOfSelector(5);
            }
            if (target.getSelectedItem().equals("Player 6 (left)")
                    && this.playerSelectorNumber == 1) {
                StatisticDialog.setPlayerOfSelector(6);
            }
            if (target.getSelectedItem().equals("Player 7 (left)")
                    && this.playerSelectorNumber == 1) {
                StatisticDialog.setPlayerOfSelector(7);
            }
            if (target.getSelectedItem().equals("Player 8 (left)")
                    && this.playerSelectorNumber == 1) {
                StatisticDialog.setPlayerOfSelector(8);
            }
            if (target.getSelectedItem().equals("Player 9 (left)")
                    && this.playerSelectorNumber == 1) {
                StatisticDialog.setPlayerOfSelector(9);
            }
            if (target.getSelectedItem().equals("Player 10 (left)")
                    && this.playerSelectorNumber == 1) {
                StatisticDialog.setPlayerOfSelector(10);
            }
            if (target.getSelectedItem().equals("Player 11 (left)")
                    && this.playerSelectorNumber == 1) {
                StatisticDialog.setPlayerOfSelector(11);
            }
            if (target.getSelectedItem().equals("Player 1 (right)")
                    && this.playerSelectorNumber == 1) {
                StatisticDialog.setPlayerOfSelector(12);
            }
            if (target.getSelectedItem().equals("Player 2 (right)")
                    && this.playerSelectorNumber == 1) {
                StatisticDialog.setPlayerOfSelector(13);
            }
            if (target.getSelectedItem().equals("Player 3 (right)")
                    && this.playerSelectorNumber == 1) {
                StatisticDialog.setPlayerOfSelector(14);
            }
            if (target.getSelectedItem().equals("Player 4 (right)")
                    && this.playerSelectorNumber == 1) {
                StatisticDialog.setPlayerOfSelector(15);
            }
            if (target.getSelectedItem().equals("Player 5 (right)")
                    && this.playerSelectorNumber == 1) {
                StatisticDialog.setPlayerOfSelector(16);
            }
            if (target.getSelectedItem().equals("Player 6 (right)")
                    && this.playerSelectorNumber == 1) {
                StatisticDialog.setPlayerOfSelector(17);
            }
            if (target.getSelectedItem().equals("Player 7 (right)")
                    && this.playerSelectorNumber == 1) {
                StatisticDialog.setPlayerOfSelector(18);
            }
            if (target.getSelectedItem().equals("Player 8 (right)")
                    && this.playerSelectorNumber == 1) {
                StatisticDialog.setPlayerOfSelector(19);
            }
            if (target.getSelectedItem().equals("Player 9 (right)")
                    && this.playerSelectorNumber == 1) {
                StatisticDialog.setPlayerOfSelector(20);
            }
            if (target.getSelectedItem().equals("Player 10 (right)")
                    && this.playerSelectorNumber == 1) {
                StatisticDialog.setPlayerOfSelector(21);
            }
            if (target.getSelectedItem().equals("Player 11 (right)")
                    && this.playerSelectorNumber == 1) {
                StatisticDialog.setPlayerOfSelector(22);
            }

        }
        StatisticDialog.action();
    }
}
